home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / RoamingJellyFish.as < prev    next >
Text File  |  2013-04-24  |  7KB  |  254 lines

  1. class RoamingJellyFish extends MovingObject
  2. {
  3.    static var sLINKAGE_NAME = "mcJellyFish";
  4.    static var nCOUNTER = 0;
  5.    static var sSTATE_STOPROAM = "StopRoam";
  6.    static var nSPEED = 1;
  7.    static var nMAX_WAIT_TIME = 75;
  8.    static var nMIN_DEPTH = 300000;
  9.    static var nDEPTH_FACTOR = 25;
  10.    function RoamingJellyFish(_nX, _nY)
  11.    {
  12.       super(CTRLGame.getRef().mcRef.attachMovie(RoamingJellyFish.sLINKAGE_NAME,RoamingJellyFish.sLINKAGE_NAME + RoamingJellyFish.nCOUNTER,CTRLGame.nMIN_DEPTH));
  13.       this.nId = RoamingJellyFish.nCOUNTER++;
  14.       this.mcRef._x = _nX;
  15.       this.mcRef._y = _nY;
  16.       this.adaptDepth();
  17.       var _loc5_ = Math.round(Math.random() * 66) + 1;
  18.       this.mcRef.mcState.jelly.jelly.gotoAndPlay(_loc5_);
  19.       this.nWaitTime = 0;
  20.       if(Controller.getRef().isPaused())
  21.       {
  22.          this.doPause();
  23.       }
  24.    }
  25.    function stopRoaming()
  26.    {
  27.       this.setState(RoamingJellyFish.sSTATE_STOPROAM);
  28.    }
  29.    function calculateDepth(_nY, _nAdd)
  30.    {
  31.       var _loc4_ = Math.round(_nY) * RoamingJellyFish.nDEPTH_FACTOR + RoamingJellyFish.nMIN_DEPTH + _nAdd;
  32.       return _loc4_;
  33.    }
  34.    function cleanUp()
  35.    {
  36.       super.cleanUp();
  37.       this.mcRef.swapDepths(7777);
  38.       this.mcRef.removeMovieClip();
  39.    }
  40.    function doPause()
  41.    {
  42.       super.doPause();
  43.       this.mcRef.mcState.jelly.jelly.stop();
  44.       this.mcRef.mcState.shadow.stop();
  45.    }
  46.    function doUnPause()
  47.    {
  48.       if(!CTRLGame.getRef().Screen.isInMiniGame())
  49.       {
  50.          super.doUnPause();
  51.          this.mcRef.mcState.jelly.jelly.play();
  52.          this.mcRef.mcState.shadow.play();
  53.       }
  54.    }
  55.    function resumeAnim()
  56.    {
  57.       super.doUnPause();
  58.       this.mcRef.mcState.jelly.jelly.play();
  59.       this.mcRef.mcState.shadow.play();
  60.    }
  61.    function adaptDepth()
  62.    {
  63.       this.mcRef.swapDepths(this.calculateDepth(this.mcRef._y,CTRLGame.nJELLYFISH_ADD + this.nId));
  64.    }
  65.    function manageMovement()
  66.    {
  67.       if(this.canMove() && this.nMovement == 0)
  68.       {
  69.          if(this.sState == MovingObject.sSTATE_DOWN || (this.sState == MovingObject.sSTATE_UP || (this.sState == MovingObject.sSTATE_LEFT || this.sState == MovingObject.sSTATE_RIGHT)))
  70.          {
  71.             this.setIdleState();
  72.          }
  73.          else if(this.isNextMoveGood(this.nCurrentDir))
  74.          {
  75.             switch(this.nCurrentDir)
  76.             {
  77.                case CTRLGame.nDIR_UP:
  78.                   this.setState(MovingObject.sSTATE_UP);
  79.                   break;
  80.                case CTRLGame.nDIR_DOWN:
  81.                   this.setState(MovingObject.sSTATE_DOWN);
  82.                   break;
  83.                case CTRLGame.nDIR_LEFT:
  84.                   this.setState(MovingObject.sSTATE_LEFT);
  85.                   break;
  86.                case CTRLGame.nDIR_RIGHT:
  87.                   this.setState(MovingObject.sSTATE_RIGHT);
  88.             }
  89.             this.nMovement = MovingObject.nMAX_MOVEMENT;
  90.          }
  91.          else
  92.          {
  93.             do
  94.             {
  95.                var _loc2_ = Math.round(Math.random() * 3);
  96.             }
  97.             while(_loc2_ == this.nCurrentDir);
  98.             
  99.             if(this.isNextMoveGood(_loc2_))
  100.             {
  101.                if(_loc2_ == CTRLGame.nDIR_UP)
  102.                {
  103.                   this.setState(MovingObject.sSTATE_UP);
  104.                }
  105.                else if(_loc2_ == CTRLGame.nDIR_DOWN)
  106.                {
  107.                   this.setState(MovingObject.sSTATE_DOWN);
  108.                }
  109.                else if(_loc2_ == CTRLGame.nDIR_LEFT)
  110.                {
  111.                   this.setState(MovingObject.sSTATE_LEFT);
  112.                }
  113.                else
  114.                {
  115.                   this.setState(MovingObject.sSTATE_RIGHT);
  116.                }
  117.                this.nCurrentDir = _loc2_;
  118.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  119.             }
  120.             else
  121.             {
  122.                this.setIdleState();
  123.             }
  124.          }
  125.       }
  126.    }
  127.    function setIdleState()
  128.    {
  129.       this.nWaitTime = RoamingJellyFish.nMAX_WAIT_TIME;
  130.       switch(this.nCurrentDir)
  131.       {
  132.          case CTRLGame.nDIR_UP:
  133.             this.setState(MovingObject.sSTATE_IDLE_UP);
  134.             break;
  135.          case CTRLGame.nDIR_DOWN:
  136.             this.setState(MovingObject.sSTATE_IDLE_DOWN);
  137.             break;
  138.          case CTRLGame.nDIR_LEFT:
  139.             this.setState(MovingObject.sSTATE_IDLE_LEFT);
  140.             break;
  141.          case CTRLGame.nDIR_RIGHT:
  142.             this.setState(MovingObject.sSTATE_IDLE_RIGHT);
  143.       }
  144.    }
  145.    function isNextMoveGood(_nNextDir)
  146.    {
  147.       var _loc3_ = this.getWishPos(_nNextDir);
  148.       var _loc4_ = this.getWishMidPos(_nNextDir);
  149.       var _loc5_ = false;
  150.       if(this.isTrackOkay(_nNextDir) && (!CTRLGame.getRef().isTouchingWall(_loc4_.x,_loc4_.y) && (!CTRLGame.getRef().isJellyTouchingDirtWall(_loc3_.x,_loc3_.y) && (!CTRLGame.getRef().isJellyTouchingAlguae(_loc3_.x,_loc3_.y) && !CTRLGame.getRef().isJellyTouchingJelly(_loc3_.x,_loc3_.y,this)))))
  151.       {
  152.          _loc5_ = true;
  153.       }
  154.       return _loc5_;
  155.    }
  156.    function IdleUp()
  157.    {
  158.       if(this.canMove())
  159.       {
  160.          if(this.nWaitTime > 0)
  161.          {
  162.             this.nWaitTime = this.nWaitTime - 1;
  163.          }
  164.          if(this.nWaitTime <= 0)
  165.          {
  166.             this.manageMovement();
  167.          }
  168.       }
  169.    }
  170.    function IdleDown()
  171.    {
  172.       if(this.canMove())
  173.       {
  174.          if(this.nWaitTime > 0)
  175.          {
  176.             this.nWaitTime = this.nWaitTime - 1;
  177.          }
  178.          if(this.nWaitTime <= 0)
  179.          {
  180.             this.manageMovement();
  181.          }
  182.       }
  183.    }
  184.    function IdleLeft()
  185.    {
  186.       if(this.canMove())
  187.       {
  188.          if(this.nWaitTime > 0)
  189.          {
  190.             this.nWaitTime = this.nWaitTime - 1;
  191.          }
  192.          if(this.nWaitTime <= 0)
  193.          {
  194.             this.manageMovement();
  195.          }
  196.       }
  197.    }
  198.    function IdleRight()
  199.    {
  200.       if(this.canMove())
  201.       {
  202.          if(this.nWaitTime > 0)
  203.          {
  204.             this.nWaitTime = this.nWaitTime - 1;
  205.          }
  206.          if(this.nWaitTime <= 0)
  207.          {
  208.             this.manageMovement();
  209.          }
  210.       }
  211.    }
  212.    function Left()
  213.    {
  214.       if(this.nMovement > 0 && this.canMove())
  215.       {
  216.          this.mcRef._x -= RoamingJellyFish.nSPEED;
  217.          this.nMovement -= RoamingJellyFish.nSPEED;
  218.       }
  219.       this.manageMovement();
  220.    }
  221.    function Up()
  222.    {
  223.       if(this.nMovement > 0 && this.canMove())
  224.       {
  225.          this.mcRef._y -= RoamingJellyFish.nSPEED;
  226.          this.nMovement -= RoamingJellyFish.nSPEED;
  227.          this.adaptDepth();
  228.       }
  229.       this.manageMovement();
  230.    }
  231.    function Right()
  232.    {
  233.       if(this.nMovement > 0 && this.canMove())
  234.       {
  235.          this.mcRef._x += RoamingJellyFish.nSPEED;
  236.          this.nMovement -= RoamingJellyFish.nSPEED;
  237.       }
  238.       this.manageMovement();
  239.    }
  240.    function Down()
  241.    {
  242.       if(this.nMovement > 0 && this.canMove())
  243.       {
  244.          this.mcRef._y += RoamingJellyFish.nSPEED;
  245.          this.nMovement -= RoamingJellyFish.nSPEED;
  246.          this.adaptDepth();
  247.       }
  248.       this.manageMovement();
  249.    }
  250.    function StopRoam()
  251.    {
  252.    }
  253. }
  254.